package com.tqjc.system.core.pipeline.service;

import cn.hutool.core.collection.CollUtil;
import com.tqjc.system.common.entity.BO.AddBusinessTaskInfo;
import com.tqjc.system.core.pipeline.BusinessProcess;
import com.tqjc.system.core.pipeline.ProcessContext;
import com.tqjc.system.core.pipeline.ProcessModel;
import com.tqjc.system.system.service.SysAddDetailTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 86195
 * @version 1.0
 * @description 获取任务明细
 * @date 2023/10/17 9:52
 */
@Service
@Slf4j
public class GetDetailTaskAction implements BusinessProcess<AddBusinessTaskInfo> {

    @Autowired
    private SysAddDetailTaskService detailTaskService;

    @Override
    public void process(ProcessContext<AddBusinessTaskInfo> context) {
        try {
            AddBusinessTaskInfo taskInfo = context.getProcessModel();
            String taskId = taskInfo.getTaskId();
            log.info("加料任务taskId：{}获取任务明细开始",taskId);
            List<String> materialList = detailTaskService.getMaterialList(taskId);

            context.setBreakFlag(true);
            if(CollUtil.isNotEmpty(materialList)){
                taskInfo.setTaskMaterialList(materialList);
                taskInfo.setMaterialNum(materialList.size());
                context.setProcessModel(taskInfo);
                //设置中止标识
                context.setBreakFlag(false);
            }
            log.info("加料任务taskId：{}获取任务明细结束",taskId);

        } catch (Exception e){
            log.error("加料任务taskId：{}获取任务明细出现异常",e);
            context.setBreakFlag(true);
        }

    }
}
